//package cn.tool.example;
//
//import cn.tool.utils.EasyExcelUtils;
//import cn.tool.utils.StringUtils;
//import com.tool.dao.mapper.JjzzMapper;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//
//import java.io.BufferedOutputStream;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import java.util.Objects;
//import java.util.stream.Collectors;
//
//
//@SpringBootTest
//public class DistinctJjzz {
//
//    @Autowired
//    JjzzMapper sysJjzzMapper;
//
//    @Test
//    public void creatReplaceOrgCode() {
//
//    }
//
//    @Test
//    public void creatSqlWords() throws IOException {
//        String filePath = "I:\\projects\\reverseEngineering\\mytool\\src\\main\\resources\\file\\a.xlsx";
//        String outFilePath = "I:\\projects\\reverseEngineering\\mytool\\src\\main\\resources\\file\\e.txt";
//
//        List<FmEconomicOrgExcel> excelAll = EasyExcelUtils.syncReadModel(filePath, FmEconomicOrgExcel.class, 0, 0);
//        ArrayList<String> sqlList = new ArrayList<>();
//        excelAll.stream().forEach(i -> {
////            List<String> tableNameList= Arrays.asList("");
//            String tableName = "fm_accounting_cashier_month";
//            String orgCode = i.getOrgCode();
//            String areaCode = i.getAreaCode();
//            String sql = "insert into " + tableName + "(`month`, `type`, `org_code`, `area_code`, `create_time`, `create_user`, `update_time`, `update_user`, `is_cancel`, `is_ending_balance`)"
//                    + "values('2022-01','ACCOUNTING'," + "'" + orgCode + "'" + "," + "'" + areaCode + "'" + ",'2022-07-08 00:00:00','zhang','2022-07-13 09:33:54','zhanghongming','0','0');";
//            String sql2 = "insert into " + tableName + "(`month`, `type`, `org_code`, `area_code`, `create_time`, `create_user`, `update_time`, `update_user`, `is_cancel`, `is_ending_balance`)"
//                    + "values('2022-01','CASHIER'," + "'" + orgCode + "'" + "," + "'" + areaCode + "'" + ",'2022-07-08 00:00:00','zhang','2022-07-13 09:33:54','zhanghongming','0','0');";
//            sqlList.add(sql);
//            sqlList.add(sql2);
//        });
////        FileOutputStream fileOutputStream = StreamUtils.get(outFilePath, false);
//        BufferedOutputStream fileOutputStream = new BufferedOutputStream(new FileOutputStream(outFilePath));
////        FileWriter fileWriter = new FileWriter(outFilePath);
//        sqlList.forEach(i -> {
//            byte[] bytes = i.getBytes();
//            try {
//                fileOutputStream.write(bytes);
//                fileOutputStream.write("\r\n".getBytes());
////                fileWriter.
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        });
//        fileOutputStream.close();
//    }
//
//    @Test
//    public void distinctJjzz() {
//        //取所有库里的经济组织
//        List<SysJjzz> databaseAll = sysJjzzMapper.selectAll();
//        Map<String, List<SysJjzz>> databaseMap = databaseAll.stream().collect(Collectors.groupingBy(SysJjzz::getName));
//
//        //取表里所有经济组织
//        String filePath = "D:\\Myproject\\reverseEngineering\\mytool\\src\\main\\resources\\file\\a.xlsx";
//        String writerFilePath = "D:\\Myproject\\reverseEngineering\\mytool\\src\\main\\resources\\file\\b.xlsx";
//        String writerFilePathC = "D:\\Myproject\\reverseEngineering\\mytool\\src\\main\\resources\\file\\c.xlsx";
//
//        List<FmEconomicOrgExcel> excelAll = EasyExcelUtils.syncReadModel(filePath, FmEconomicOrgExcel.class, 0, 2);
//        excelAll.stream().forEach(i -> {
//            i.setName(getName(i.getName()));
//        });
//        Map<String, List<FmEconomicOrgExcel>> excelMap = excelAll.stream().collect(Collectors.groupingBy(FmEconomicOrgExcel::getName));
//        ArrayList<String> nameList = new ArrayList<>();
//        ArrayList<OutPutExcelDo> excelList = new ArrayList<>();
//        ArrayList<OutPutExcelDo> excelListC = new ArrayList<>();
//
//        databaseMap.keySet().forEach(name -> {
//            List<SysJjzz> databaseDos = databaseMap.get(name);
//            List<FmEconomicOrgExcel> excelDos = excelMap.get(name);
//            if (!Objects.isNull(databaseDos) && !Objects.isNull(excelDos)) {
//                int excelSize = excelDos.size();
//                int databaseSize = databaseDos.size();
//                int max = excelSize > databaseSize ? excelSize : databaseSize;
//                for (int i = 0; i < max; i++) {
//                    OutPutExcelDo outPutExcelDo = new OutPutExcelDo(name);
//                    if (i < excelSize) {
//                        FmEconomicOrgExcel excelDo = excelDos.get(i);
//                        outPutExcelDo.setName(excelDo.getName());
//                        outPutExcelDo.setAddr(excelDo.getAddr());
//                        outPutExcelDo.setClassType(excelDo.getClassType());
//                        outPutExcelDo.setOrgCode(excelDo.getOrgCode());
//                    }
//                    if (i < databaseSize) {
//                        SysJjzz databaseDO = databaseDos.get(i);
//                        outPutExcelDo.setOldName(databaseDO.getName());
//                        outPutExcelDo.setOldOrgCode(databaseDO.getCode());
//                    }
//                    excelList.add(outPutExcelDo);
//                }
//                nameList.add(name);
//            } else if (!Objects.isNull(databaseDos) && Objects.isNull(excelDos)) {
//                int databaseSize = databaseDos.size();
//                for (int i = 0; i < databaseSize; i++) {
//                    OutPutExcelDo outPutExcelDo = new OutPutExcelDo(name);
//                    if (i < databaseSize) {
//                        SysJjzz databaseDO = databaseDos.get(i);
//                        outPutExcelDo.setOldName(databaseDO.getName());
//                        outPutExcelDo.setOldOrgCode(databaseDO.getCode());
//                    }
//                    excelList.add(outPutExcelDo);
//                }
//            }
//        });
//
//        for (String s : excelMap.keySet()) {
//            if (!nameList.contains(s)) {
//                List<FmEconomicOrgExcel> fmEconomicOrgExcels = excelMap.get(s);
//                fmEconomicOrgExcels.forEach(item -> {
//                    OutPutExcelDo outPutExcelDo = new OutPutExcelDo();
//                    outPutExcelDo.setName(item.getName());
//                    outPutExcelDo.setOrgCode(item.getOrgCode());
//                    outPutExcelDo.setClassType(item.getClassType());
//                    outPutExcelDo.setAddr(item.getAddr());
//                    excelList.add(outPutExcelDo);
//                });
//            }
//        }
//        EasyExcelUtils.write(writerFilePath, OutPutExcelDo.class, excelList);
////        EasyExcelUtils.write(writerFilePathC, OutPutExcelDo.class, excelListC);
//    }
//
//    private String getName(String name) {
//        if (StringUtils.contains(name, "镇") && StringUtils.contains(name, "股份经济合作社")) {
//            return name.substring(name.indexOf("镇") + 1, name.indexOf("股份经济合作社"));
//        }
//        return name;
//    }
//
//    @Test
//    public void distinctJjzz1() {
//        //取所有库里的经济组织
//        List<SysJjzz> databaseAll = sysJjzzMapper.selectAll();
//        Map<String, List<SysJjzz>> databaseMap = databaseAll.stream().collect(Collectors.groupingBy(SysJjzz::getPcode));
//        //取表里所有经济组织
//        String filePath = "D:\\Myproject\\reverseEngineering\\mytool\\src\\main\\resources\\file\\a.xlsx";
//        String writerFilePath = "D:\\Myproject\\reverseEngineering\\mytool\\src\\main\\resources\\file\\b.xlsx";
//        String writerFilePathC = "D:\\Myproject\\reverseEngineering\\mytool\\src\\main\\resources\\file\\c.xlsx";
//        List<FmEconomicOrgExcel> excelAll = EasyExcelUtils.syncReadModel(filePath, FmEconomicOrgExcel.class, 0, 2);
//        Map<String, List<FmEconomicOrgExcel>> excelMap = excelAll.stream().collect(Collectors.groupingBy(FmEconomicOrgExcel::getAreaCode));
//        ArrayList<OutPutExcelDo> excelList = new ArrayList<>();
//        ArrayList<OutPutExcelDo> excelListC = new ArrayList<>();
//
//        databaseMap.keySet().forEach(aredCode -> {
//            List<FmEconomicOrgExcel> excelDos = excelMap.get(aredCode);
//            List<SysJjzz> databaseDos = databaseMap.get(aredCode);
//            if (!Objects.isNull(excelDos) && !Objects.isNull(databaseDos)) {
//                if (excelDos.size() == databaseDos.size()) {
//                    int max = excelDos.size();
//                    System.out.println("该行政区划下的经济组织数量相同" + aredCode);
//                    for (int i = 0; i < max; i++) {
//                        OutPutExcelDo outPutExcelDo = new OutPutExcelDo(aredCode);
//
//                        FmEconomicOrgExcel excelDo = excelDos.get(i);
//                        outPutExcelDo.setName(excelDo.getName());
//                        outPutExcelDo.setAddr(excelDo.getAddr());
//                        outPutExcelDo.setClassType(excelDo.getClassType());
//                        outPutExcelDo.setOrgCode(excelDo.getOrgCode());
//
//                        SysJjzz databaseDO = databaseDos.get(i);
//                        outPutExcelDo.setOldName(databaseDO.getName());
//                        outPutExcelDo.setOldOrgCode(databaseDO.getCode());
//
//                        excelListC.add(outPutExcelDo);
//                    }
//                    excelListC.add(new OutPutExcelDo());
//                } else {
//                    int excelSize = excelDos.size();
//                    int databaseSize = databaseDos.size();
//                    int max = excelSize > databaseSize ? excelSize : databaseSize;
//                    for (int i = 0; i < max; i++) {
//                        OutPutExcelDo outPutExcelDo = new OutPutExcelDo(aredCode);
//                        if (i < excelSize) {
//                            FmEconomicOrgExcel excelDo = excelDos.get(i);
//                            outPutExcelDo.setName(excelDo.getName());
//                            outPutExcelDo.setAddr(excelDo.getAddr());
//                            outPutExcelDo.setClassType(excelDo.getClassType());
//                            outPutExcelDo.setOrgCode(excelDo.getOrgCode());
//                        }
//                        if (i < databaseSize) {
//                            SysJjzz databaseDO = databaseDos.get(i);
//                            outPutExcelDo.setOldName(databaseDO.getName());
//                            outPutExcelDo.setOldOrgCode(databaseDO.getCode());
//                        }
//                        excelList.add(outPutExcelDo);
//                    }
//                    excelList.add(new OutPutExcelDo());
//                }
//            } else {
//                int databaseSize = databaseDos.size();
//                for (int i = 0; i < databaseSize; i++) {
//                    OutPutExcelDo outPutExcelDo = new OutPutExcelDo(aredCode);
//                    if (i < databaseSize) {
//                        SysJjzz databaseDO = databaseDos.get(i);
//                        outPutExcelDo.setOldName(databaseDO.getName());
//                        outPutExcelDo.setOldOrgCode(databaseDO.getCode());
//                    }
//                    excelList.add(outPutExcelDo);
//                }
//                excelList.add(new OutPutExcelDo());
//            }
//        });
//        EasyExcelUtils.write(writerFilePath, OutPutExcelDo.class, excelList);
//        EasyExcelUtils.write(writerFilePathC, OutPutExcelDo.class, excelListC);
//    }
//}
